package Aleehot100;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * ClassName: c036
 * Package: Aleehot100
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/7/6 12:27
 * @Version 1.0
 * @Since 1.0
 */
public class c036 {
    public static void main(String[] args) {

    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }

        static List<Integer> res = new ArrayList<>();

        public static List<Integer> inorderTraversal(TreeNode head) {

            res.clear();
            if (null == head) {
                return new ArrayList<>();
            }
            // 递归方式写
            inorder(head);

            return res;
        }

        private static void inorder(TreeNode head) {
            if (head == null) {
                return;
            }
            inorder(head.left);
            res.add(head.val);
            inorder(head.right);
        }


    }


//    public List<Integer> inorderTraversal(TreeNode head) {
//        List<Integer> list = new ArrayList<>();
//        if (head == null) {
//            return list;
//        }
//        TreeNode cur = head;
//        Stack<TreeNode> stack = new Stack<>();
//        while (cur != null || !stack.isEmpty()) {
//            if (cur != null) {
//                stack.push(cur);
//                cur = cur.left;
//            } else {
//                cur = stack.pop();
//                list.add(cur.val);
//                cur = cur.right;
//            }
//        }
//        return list;
//    }
}
